import java.util.*;

public class Test {
    public static void main(String[] args) {

    }



    // 删除链表中重复的结点
    /*
    public ListNode deleteDuplication(ListNode pHead) {
        ListNode newHead = new ListNode(0);
        ListNode cur = newHead;
        while (pHead != null){
            // 如果是最后一个结点, 或者当前结点与后面结点不同, 加入新链表
            if(pHead.next == null || pHead.next.val != pHead.val){
                cur.next = pHead;
                // cur 后移
                cur = pHead;
            }
            // 如果当前结点与后面结点相同, 跳过这两个结点
            while(pHead.next != null && pHead.next.val == pHead.val){
                pHead = pHead.next;
            }
            pHead = pHead.next;
        }
        // 当最后两个结点是相同时, cur.next需要置空
        cur.next = null;
        return newHead.next;
    }
     */



    // 下一个更大元素 I
    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
        Deque<Integer> stack = new ArrayDeque<>();
        Map<Integer, Integer> map = new HashMap<>();

        // 从后向前遍历数组nums2
        for (int i = nums2.length - 1; i >= 0; i--) {
            int num = nums2[i];
            // 栈不空, 且大于栈顶元素
            while (!stack.isEmpty() && num > stack.peek()) {
                stack.pop();
            }
            // 如果栈为空,说明右侧没有更大的值
            map.put(num, stack.isEmpty() ? -1 : stack.peek());
            // 入栈
            stack.push(num);
        }
        int[] res = new int[nums1.length];
        for (int i = 0; i < res.length; i++) {
            res[i] = map.get(nums1[i]);
        }
        return res;
    }



    // 用栈操作构建数组
    public List<String> buildArray(int[] target, int n) {
        List<String> list = new ArrayList<>();
        for (int i = 1,j = 0; i <= n && j < target.length; i++) {
            list.add("Push");
            if (i == target[j]) {
                j++;
            } else {
                list.add("Pop");
            }
        }
        return list;
    }



    // 点击消除
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        StringBuilder sb = new StringBuilder(s.length());
        int j = -1;
        for (int i = 0; i < s.length(); i++) {
            if (j == -1 || sb.charAt(j) != s.charAt(i)) {
                sb.append(s.charAt(i));
                j++;
            } else {
                sb.deleteCharAt(j);
                j--;
            }
        }
        System.out.println(sb.length() == 0 ? 0 : sb.toString());
    }
}
